cmake_minimum_required(VERSION 3.5.0)
project(ElectricityConsumptionTerminal VERSION 1.0.0 LANGUAGES C CXX)

# Used to generate config.h.
string(TOUPPER ${PROJECT_NAME} CONFIG_PROJECT_NAME)

# Basic Information.
MESSAGE(STATUS "CMake version: " ${CMAKE_VERSION})
MESSAGE(STATUS "CMake system name: " ${CMAKE_SYSTEM_NAME})

# Macro to provide an option dependent on other options.
include(CMakeDependentOption)

# Provides a macro to check if a list of one or more header files can be included together in C.
include(CheckIncludeFiles)

# Check if a C function can be linked.
include(CheckFunctionExists)

# Check if a symbol exists as a function, variable, or macro.
include(CheckSymbolExists)

# Provides install directory variables as defined by the GNU Coding Standards.
# GNU Coding Standards Reference 'https://www.gnu.org/prep/standards/html_node/Directory-Variables.html'.
include(GNUInstallDirs)

# Check whether the CXX compiler supports a given flag.
include(CheckCXXCompilerFlag)

if(NOT CMAKE_INSTALL_RPATH AND CMAKE_INSTALL_PREFIX)
    set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
    link_directories(${CMAKE_INSTALL_FULL_LIBDIR})
    message(STATUS "Setting install rpath to ${CMAKE_INSTALL_RPATH}")
endif()

set (CMAKE_CXX_STANDARD 17)

# Provides an option that the user can optionally select.
option(ENABLE_TESTER "Build tester binary." OFF)

# add extra infos to binary files, such as value of MACROs
# list(APPEND STRICT_OPTIONS_CPP "-g3" "-gdwarf-2")
# list(APPEND STRICT_OPTIONS_C "-g3" "-gdwarf-2")
# list(APPEND STRICT_OPTIONS_CXX "-g3" "-gdwarf-2")

if (ENABLE_GPROF)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg")
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg")
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
    SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -pg")
endif()

find_package(Threads)

if (CMAKE_SYSTEM_NAME MATCHES "Linux")
    add_definitions("-D__linux__")
elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
    add_definitions("-D__WIN32__")
endif()

add_subdirectory(include)
add_subdirectory(src)
if (ENABLE_TESTER)
    add_subdirectory(tester)
endif()
